package com.bdqn.servlet.emp;

import com.bdqn.entity.CheckWork;
import com.bdqn.entity.PageBean;
import com.bdqn.service.Impl.PageQueryServiceImpl;
import com.bdqn.service.PageQueryService;
import com.bdqn.util.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "PageQueryServlet",urlPatterns = "/PageQuery")
public class PageQueryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String end = request.getParameter("end");
        String start = request.getParameter("start");
        String empId = request.getParameter("empId");
        String strcurrentPage = request.getParameter("currentPage");
        int currentPage = 1;
        if(strcurrentPage!=null && strcurrentPage.length()>0 && !"null".equals(strcurrentPage)){
            currentPage = Integer.parseInt(strcurrentPage);
        }
        String strpageSize = request.getParameter("pageSize");
        int pageSize = 1;
        if(strpageSize!=null && strpageSize.length()>0 && !"null".equals(strpageSize)){
            pageSize = Integer.parseInt(strpageSize);
        }
        PageQueryService service = new PageQueryServiceImpl();

        if(end == null || end.equals("null") || end.length()<=0){
            PageBean<CheckWork>  pb =service.findByPage(empId,currentPage,pageSize);
            JSON.writeAsString(pb,response);
        }else{
            PageBean<CheckWork> pb =service.findByPage(empId,currentPage,pageSize,end,start);
            JSON.writeAsString(pb,response);
        }
        //PageBean<CheckWork> pb =service.findByPage(empId,currentPage,pageSize);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
